<?php
namespace app\index\service;

use app\index\model\LabourGongModel;
use app\index\model\LabourJieModel;
use app\index\model\LabourLingModel;
use app\index\model\LabourShenModel;
use app\index\model\LabourYongModel;

class LabourService extends CommonService
{

    public function create_labour_shen_number(){
        $tou = 'JDKSB';
        $daystr = substr(date("Ymd"), 2);
        $number = LabourShenModel::where('number','like','%'.$tou.$daystr.'%')->order('number DESC')->value('number');
        if(!$number){
            $str = $tou.$daystr.'00001';
        }else{
            $str = $tou.((int)str_replace($tou,'',$number)+1);
        }
        return $str;
    }

    public function create_labour_jie_number(){
        $tou = 'WGJS';
        $daystr = substr(date("Ymd"), 2);
        $number = LabourJieModel::where('number','like','%'.$tou.$daystr.'%')->order('number DESC')->value('number');
        if(!$number){
            $str = $tou.$daystr.'00001';
        }else{
            $str = $tou.((int)str_replace($tou,'',$number)+1);
        }
        return $str;
    }

    public function create_labour_ling_number(){
        $tou = 'LXLWD';
        $daystr = substr(date("Ymd"), 2);
        $number = LabourLingModel::where('number','like','%'.$tou.$daystr.'%')->order('number DESC')->value('number');
        if(!$number){
            $str = $tou.$daystr.'00001';
        }else{
            $str = $tou.((int)str_replace($tou,'',$number)+1);
        }
        return $str;
    }





    public function get_labour_gong_yongxing(){
        return [
            '自有工人',
            '劳务分包',
            '临时用工',
        ];
    }

    public function get_labour_gong_gonglei(){
        return [
            '按时',
            '按日',
            '按月',
            '按量',
        ];
    }


    public function check_labour_gong_name($name, $idcard, $id=0){
        return !!LabourGongModel::where(['comid'=>$this->userinfo['comid'],'name'=>$name,'idcard'=>$idcard,'deleted_user'=>0])->where('id','neq', $id)->find();
    }

    public function check_labour_ban_name($name, $id=0){
        return !!LabourGongModel::where(['comid'=>$this->userinfo['comid'],'name'=>$name,'deleted_user'=>0])->where('id','neq', $id)->find();
    }


    public function create_labour_yong_number(){
        $tou = 'YGD';
        $daystr = substr(date("Ymd"), 2);
        $number = LabourYongModel::where('number','like','%'.$tou.$daystr.'%')->order('number DESC')->value('number');
        if(!$number){
            $str = $tou.$daystr.'00001';
        }else{
            $str = $tou.((int)str_replace($tou,'',$number)+1);
        }
        return $str;
    }

}
